import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QFileDialog, QLabel,QLineEdit
from PyQt5.QtGui import QPixmap

def show_file_dialog():
    app = QApplication(sys.argv)
    window = QWidget()
    window.setGeometry(300, 50, 800, 600)
    window.setWindowTitle('Simple Image Viewer')

    file_path_edit = QLineEdit(window)
    file_path_edit.setGeometry(50, 30, 400, 30) # 参数意义  ：x坐标，y坐标，宽度，高度

    image_label = QLabel(window)
    image_label.setGeometry(50, 100, 400, 300)

    choose_file_button = QPushButton('Choose Image', window)
    choose_file_button.setGeometry(500, 30, 100, 30)

    def handle_button_click():
        options = QFileDialog.Options()
        file_name, _ = QFileDialog.getOpenFileName(window, "Select Image", ".", "Images (*.png *.jpg *.jpeg);;All Files (*)", options=options)
        if file_name:
            file_path_edit.setText(file_name)
            pixmap = QPixmap(file_name)
            image_label.setPixmap(pixmap.scaled(image_label.size(), aspectRatioMode=1))

    choose_file_button.clicked.connect(handle_button_click)

    window.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    show_file_dialog()